<template>
<!-- transition是加动画效果 -->
<transition name="a">
 <!-- @click.self避免冒泡，只有点击自己时才能触发   -->
  <div class="lr-dialog_wrapper" v-show="visivle" @click.self="close">
      <div class="lr-dialog" :style="{width:width,marginTop:top}">
          <div class="lr-dialog_header">
              <span class="lr-dialog_title">{{title}}</span>
              <button class="lr-dialog_headerbtn" @click="close">
                  <span class="iconfont ">&#xe652;</span>
              </button>
          </div>
          <div class="lr-dialog_body">
              <!-- 默认插槽 -->
              <slot></slot>
          </div>
           <!-- 如果footer不传递内容，则不显示footer -->
          <div class="lr-dialog_footer" v-if="$slots.footer">
              <slot name="footer" ></slot>
          </div>
      </div>
  </div>
</transition>
</template>

<script>
export default {
    name:'LrDialog',
    props:{
        title:{
            type:String,
            default:'提示'
        },
        width:{
            type:String,
            default:'34%'
        },
        top:{
            type:String,
            default:'15vh'
        },
        visivle:{
            type:Boolean,
            default:'false'
        }
    },
    methods: {
        close(){
            this.$emit('update:visivle',false)
        }
    },

}
</script>

<style lang="scss" scoped>
.lr-dialog_wrapper{
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: auto;
  margin: 0;
  z-index: 2001;
  background-color: rgba(0,0,0,0.5);
  .lr-dialog{
    position: relative;
    margin: 15vh auto 50px;
    background: #fff;
    border-radius: 2px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    box-sizing: border-box;
    width: 30%;
    &_header{
      padding: 20px 20px 10px;
      .lr-dialog_title{
        line-height: 24px;
        font-size: 18px;
        color: #303133;
      }
      .lr-dialog_headerbtn{
        position: absolute;
        top: 20px;
        right: 20px;
        padding: 0;
        background: transparent;
        border: none;
        outline: none;
        cursor: pointer;
        font-size: 16px;
        .lr-icon-close{
          color:909399
        }
      }
    }
    &_body{
      padding: 30px 20px;
      color: #606266;
      font-size: 14px;
      word-break: break-all;
    }
    &_footer{
      padding: 10px 20px 20px;
      text-align: right;
      box-sizing: border-box;
        // 深度选择器 scss ::v-deep  less /deep/  css >>>  
        //  其作用是在vue中可以对此其他组件也其作用，如这里就是让父组件享受的css效果
      ::v-deep .lr-button:first-child{
        margin-right: 20px;
      }
    }
  }
}
.a-enter-active{
  animation: fade .3s;
}
.a-leave-active{
  animation: fade .3s reverse;
}
@keyframes fade{
  0% {
    opacity: 0;
    transform: translateY(-40px);
  }
  100%{
    opacity: 1;
    transform: translateY(0);
  }
}
</style>